<?php
namespace app\model;

class LearningRecord extends BaseModel
{
    protected $name = 'learning_records';

    // 自动时间戳
    protected $autoWriteTimestamp = true;

    // 类型转换
    protected $type = [
        'last_study_at' => 'integer',
        'created_at' => 'integer',
        'updated_at' => 'integer',
        'delete_time' => 'integer'
    ];

    // 学习类型常量
    const TYPE_REVIEW = 1;  // 复习模式
    const TYPE_EXAM = 2;    // 考试模式

    // 完结状态常量
    const STATUS_IN_PROGRESS = 0; // 进行中
    const STATUS_COMPLETED = 1;   // 已完成
    const STATUS_INTERRUPTED = 2; // 已中断

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 关联课程
     */
    public function course()
    {
        return $this->belongsTo(CourseOutline::class, 'course_id');
    }

    /**
     * 关联教案
     */
    public function teachingPlan()
    {
        return $this->belongsTo(TeachingPlan::class, 'teaching_plan_id');
    }

    /**
     * 关联得分记录
     */
    public function scoreDetails()
    {
        return $this->hasMany(ScoreDetail::class, 'learning_record_id');
    }

    /**
     * 关联当前教案
     */
    public function currentPlan()
    {
        return $this->belongsTo(TeachingPlan::class, 'current_plan_id');
    }

    /**
     * 关联当前教案元素
     */
    public function currentElement()
    {
        return $this->belongsTo(TeachingPlanElement::class, 'current_element_id');
    }
} 